package yja.gzw.app.activity

import android.util.Log
import android.widget.Toast
import androidx.lifecycle.Observer
import yja.gzw.app.R
import yja.gzw.app.base.BaseActivity
import yja.gzw.app.databinding.ActivityGenghuanshoujihaoBinding
import yja.gzw.app.model.UserData
import yja.gzw.app.viewmodel.Mainviewmodel

class GenghuanshoujihaoActivity :BaseActivity<Mainviewmodel, ActivityGenghuanshoujihaoBinding>(R.layout.activity_genghuanshoujihao){
    override fun initView() {
        binding.yanjing2.setOnClickListener {
            val shoujihao=binding.emilName2.text.toString()
            viewmodel.onzhuceyzmwang(mapOf("mobile" to shoujihao ,"event" to "mobilelogin"))
            Toast.makeText(this,"获取验证码中请稍后...", Toast.LENGTH_SHORT).show()

        }

        binding.xinyanjing2.setOnClickListener {
            val shoujihao=binding.xinemilName2.text.toString()
            viewmodel.onzhuceyzmwang(mapOf("mobile" to shoujihao ,"event" to "mobilelogin"))
            Toast.makeText(this,"获取验证码中请稍后...", Toast.LENGTH_SHORT).show()

        }


        binding.chunzhi.setOnClickListener {
            viewmodel.ongenhuanshoujihaowang(UserData.token, mapOf("old_mobile" to binding.emilName2.text.toString(),"old_captcha" to binding.emilPaw2.text.toString(),"mobile" to binding.xinemilName2.text.toString(),"captcha" to binding.xinemilPaw2.text.toString()))


        }



    }

    override fun dataObservese() {
        viewmodel.ongenhuanshoujihao.observe(this, Observer {
            if(it.code==1){
                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
                finish()
            }else{

                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
            }

        })


        viewmodel.onzhuceyzm.observe(this, Observer {
            Log.e("开始","111")
            if(it.code==1){
                Log.e("开始","222")
                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
            }else{
                Log.e("开始","333")
                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
            }

        })




    }
}